n, d = map(int, input().split())

Q = [list(map(int, input().split())) for _ in range(n)]
K = [list(map(int, input().split())) for _ in range(n)]
V = [list(map(int, input().split())) for _ in range(n)]
W = list(map(int, input().split()))

# k 的转置,实际上用不着
# K_T = [ [ row[i] for row in k ] for i in range(d)]

# WQK,结果是n*n矩阵
WQK = []
for i in range(n):
    ROW = []  # WQK矩阵的行
    q = Q[i]  # Q 的第i行

    for j in range(n):  # k一共有n行
        sum = 0
        k = K[j]

        for x in range(d):  # 共有d列
            sum += (q[x] * k[x])

        ROW.append(sum * W[i])  # ROW是1*n的列表

    WQK.append(ROW)

##for k in range(len(WQK)):
##    print(WQK[k])

# 再乘V,实际上用V的转置更容易
V_t = [[row[i] for row in V] for i in range(d)]  # V是n*d

matrix = []  # (n*n)*(n*d) = n*d
for i in range(n):
    ROW = []
    wqk = WQK[i]

    for j in range(d):  # V_t是d行n列
        v = V_t[j]
        sum = 0

        for x in range(n):
            sum += wqk[x] * v[x]

        ROW.append(sum)

    matrix.append(ROW)

##
##for k in range(len(matrix)):
##    print(matrix[k])
##

for i in range(n):
    for j in range(d):
        print(matrix[i][j], end=" ")
    print("")